package com.team.h;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.team.arms.SmartArmsApplication8081;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @Author huazige
 * @Date 2022/6/2 12:04
 * @Version 1.0
 */
@SpringBootTest(classes = SmartArmsApplication8081.class)
public class CodeGenerator {



    @Test
    public void generator(){
        String projectPath = System.getProperty("user.dir");
        FastAutoGenerator.create("jdbc:mysql://120.77.156.205:3307/zhengbingwang?userSSL=false&useUnicode=true&characterEncoding=utf-8?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8", "root", "WuZhuang!#0410.")
                .globalConfig(builder -> {
                    builder.author("Huazige") // 设置作者
                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(projectPath+"/src/main/java/com/team/arms/xitong"); // 指定输出目录

                })
                .packageConfig(builder -> {
                    builder.parent("com.team.arms.xitong"); // 设置父包名
                    //.moduleName("system") // 设置父包模块名
//                            .pathInfo(Collections.singletonMap(OutputFile.mapperXml, projectPath+"src/main/java/com/haotongxue/course_service/com.haotongxue.mapper/xml")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("x_data_mamage") // 设置需要生成的表名
                            .addTablePrefix("x_") // 设置过滤表前缀
                            .entityBuilder()
                            .enableLombok()
//                            .versionColumnName("version") //乐观锁
//                            .logicDeleteColumnName("is_deleted") //逻辑删除
//                            .logicDeletePropertyName("isDeleted")
                            .idType(IdType.ASSIGN_ID)
//                            .addTableFills(new Column("create_time", FieldFill.INSERT))
//                            .addTableFills(new Column("update_time", FieldFill.INSERT_UPDATE))
                            .controllerBuilder()
                            .enableRestStyle();
                })
                //.templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }
}
